'use strict';

module.exports = app => {
  const { STRING, BOOLEAN, UUID } = app.Sequelize;

  const User = app.model.define('user', {
    id: { type: UUID, primaryKey: true },
    nickName: { type: STRING, allowNull: false },
    avatar: { type: STRING, allowNull: false },
    sex: {
      type: BOOLEAN,
      allowNull: false,
      get() {
        if (this.getDataValue('sex')) {
          return '男'
        } else {
          return '女'
        }
      }
    }
  });

  User.associate = function () {
    // hasMany  belongTo
    app.model.User.hasMany(app.model.Order, {
      foreignKey: 'UserId',
      targetKey: 'id'
    })
  }
}
